import Vue from 'vue'
import App from './App.vue'
import router from './router';
import store from './store';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI)

Vue.config.productionTip = false

let vue = new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')

// 全局前置守卫
router.beforeEach((to, from, next) => {
  let CASTGC = vue.$store.state.CASTGC
  if(CASTGC === '' && to.path !== '/login') {
    // 用户未登录
    vue.$router.replace('/login')
  }else if(CASTGC !== '') {
    // 用户已登录
    if(to.path === '/login') {
      // 直接跳回首页
      vue.$router.replace('/home')
    }
  }
  next()
})